home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Sept, 2002
- // Author: bb
- //
- // Procedure Name:
- // doModifyConstraintAxes
- //
- // Description:
- // The user selects the constrained object.
- // This script restricts the axes affected by the constraint.
- //
- // Input Arguments:
- // $version: The version of this option box. Used to know how to
- // interpret the $args array.
- // "1" : first verison of nla
- //
- // $args
- // Version 1
- // [0] $constrainX : whether or not to constrain x
- // [1] $constrainY : whether or not to constrain y
- // [2] $constrainY : whether or not to constrain z
- // [3] $maintainOffset: whether to maintain the existing offset to the remaining targets
- //
- // Return Value:
- // none
- //
-
-
- global proc
- doModifyConstraintAxes( string $version, string $args[] )
- {
- string $sels[] = `ls -sl`;
- if (size($sels) == 0) {
- error("You must select the constrained object.");
- return;
- }
-
- string $cmd;
- int $constrainX = $args[0];
- int $constrainY = $args[1];
- int $constrainZ = $args[2];
- int $maintainOffset = $args[3];
-
- string $flags = " -e";
- string $parentFlags = " -e";
- if (! $constrainX) {
- $flags += " -skip x";
- $parentFlags += " -skipRotate x -skipTranslate x";
- }
- if (! $constrainY) {
- $flags += " -skip y";
- $parentFlags += " -skipRotate y -skipTranslate y";
- }
- if (! $constrainZ) {
- $flags += " -skip z";
- $parentFlags += " -skipRotate z -skipTranslate z";
- }
- if ($flags == " -e") {
- $flags += " -skip none";
- $parentFlags += " -skipRotate none -skipTranslate none";
- }
-
- if (0 == ($constrainX + $constrainY + $constrainZ)) {
- error("No axes were selected.");
- return;
- }
-
- if ($maintainOffset) {
- $flags += " -maintainOffset; ";
- $parentFlags += " -maintainOffset; ";
- } else {
- // Reset the offset of the constraint back to 0 0 0 if maintainOffset
- // is turned off.
- //
- $flags += " -offset 0 0 0; ";
- $parentFlags += "; ";
- }
-
- for ($constrainedObj in $sels) {
- string $p1 = `pointConstraint -q $constrainedObj`;
- if (size($p1)) {
- $cmd += "pointConstraint"+$flags;
- }
- string $a1 = `aimConstraint -q $constrainedObj`;
- if (size($a1)) {
- $cmd += "aimConstraint"+$flags;
- }
- string $o1 = `orientConstraint -q $constrainedObj`;
- if (size($o1)) {
- $cmd += "orientConstraint"+$flags;
- }
- string $s1 = `scaleConstraint -q $constrainedObj`;
- if (size($s1)) {
- $cmd += "scaleConstraint"+$flags;
- }
- string $p2 = `parentConstraint -q $constrainedObj`;
- if (size($p2)) {
- $cmd += "parentConstraint"+$parentFlags;
- // Get the parent constraint from the constrained object
- //
- string $constrainedRelatives[] =
- `listRelatives -type "parentConstraint" $constrainedObj`;
- if ( !$maintainOffset && `size $constrainedRelatives` == 1 )
- {
- // If maintainOffset is not specified reset the offsets on the
- // constraint node. If there is not exactly 1 parent
- // constraint then don't attempt to set the offsets to 0 0 0.
- //
-
- $parentConstraint = $constrainedRelatives[ 0 ];
-
- // Get the name of each targetOffsetRotate and
- // targetOffsetTranslate attribute on the constraint node.
- //
- $cmd += "string $parentConstraintOffsetAttrs[] = ";
- $cmd += " `listAttr -st \"targetOffsetTranslate\" ";
- $cmd += " -st \"toffsetRotate\" ";
- $cmd += ( " -m \""+$parentConstraint+".target\"`;");
-
- $cmd += "string $offsetAttr; ";
-
- // Set each targetOffset attribute on the node to 0 0 0.
- // This ensures that if the user
- //
- $cmd += "for ( $offsetAttr in $parentConstraintOffsetAttrs ) ";
- $cmd += "{";
- $cmd += ("setAttr (\""+ $parentConstraint +".\"+$offsetAttr)");
- $cmd += " 0 0 0;";
- $cmd += "}";
- }
- }
- }
- if (size($cmd) == 0) {
- error("An aim-, orient-, parent-, point-, or scale-constrained object must be the last object selected.");
- }
- evalEcho $cmd;
- }
-